#!/bin/bash


function on_off () {
  if [ $# == 0 ]
  then
    echo ON
  fi
  par=$(echo $1 | tr '[:upper:]' '[:lower:]')
  case $1 in
    on*)
      echo ON
      ;;
    off*)
      echo OFF
      ;;
    en*)
      echo ON
      ;;
    dis*)
      echo OFF
      ;;
    *)
      echo ON
   esac;
}


# read the current opts from meta
opts=$(adapt query self opts)

while [ $# -gt 0 ]
do
  par=$1
  opt=${par%%=*}
  val=${par##*=}
  echo $opt $val 1>&2
  # normalize val
  # in another implementation on_off may be a script (called with oop)
  val=$(on_off $val)
  # generate options only for new options
  if [[ "$opts" != *$opt=$val* ]]
  then
    opts=$opt=$val:$opts
    new_options=yes
  fi
  shift
done

# are some new options detected?
if [ ${new_options:-no} == no ]
then
  echo no
else
  adapt register self opts="'$opts'"
  echo yes
fi
